<?php

defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'getorder';
if($_RQ['op']=='getorder'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'plugin_name'=>'jy_pingdd','mid'=>$_SESSION['uid'],'is_team'=>1);
	if(isset($_RQ['status']) && $_RQ['status']!=100){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=intval($_RQ['status']);
	}else{
		$return['params']['status']=100;
	}
	//我的团
	//先查询我的订单
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getslice('jy_weishop_order',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($list){
		foreach($list as $k=>&$item){
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$goodsid=pdo_getcolumn('jy_weishop_order_goods',array('uniacid'=>$_SESSION['uniacid'],'orderid'=>$item['id']),'goodsid');
			$item['goods']=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$goodsid));
			if($item['goods']['groupprice']==0){
				$return['pluginset']['groupdiscount']=$return['pluginset']['groupdiscount']?:98;
				$item['goods']['groupprice'] =$item['goods']['price']*$return['pluginset']['groupdiscount']/100;
			}
			if(!$item['goods']['id']){
				unset($list[$k]);
			}
			if($item['teamid']){
				$item['team']=pdo_get('jy_weishop_groups_team',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['teamid']));
			}
			
		}
	}
	$return['list']=$list;
	//print_r($return);exit;
	exi($return);
}
if($_RQ['op']=='getlist'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	$params['status']=intval($_RQ['status']);
	$return['params']['status']=intval($_RQ['status']);
	//我的团
	//先查询我的订单
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$teams=pdo_getslice('jy_weishop_groups_team',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($teams){
		foreach($teams as $k=>&$item){
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['goods']=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['goodsid']));
			if($item['goods']['groupprice']==0){
				$return['pluginset']['groupdiscount']=$return['pluginset']['groupdiscount']?:98;
				$item['goods']['groupprice'] =$item['goods']['price']*$return['pluginset']['groupdiscount']/100;
			}
			if(!$item['goods']['id']){
				unset($teams[$k]);
			}
			$item['order']=pdo_get('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'teamid'=>$item['id'],'mid'=>$item['mid']));
		}
	}
	$return['list']=$teams;
	exi($return);
}
if($_RQ['op']=='pay'){
	$id = intval($_RQ['id']);
	if(!$id){
		exi('订单不存在，请重新选择订单','error');
	}
	$pay_id=pdo_getcolumn('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id),'pay_id');
	exi($pay_id);
}
